<?php
include("./include/config.php");
include("./include/db.php");
include ("Pager/Pager.php");
$db = new db();
if (!$db->connect()) exit(mysql_error);
if (isset($_GET['d'])) {
    $d = (int)$_GET['d'];
    if ($d > 0) {
        $db->sql = "DELETE FROM lejarat WHERE id='$d'";
        $db->query();
    }
}
#sortable#
if (isset($_GET['o'])) {
    $o = (int)$_GET['o'];
    $r = (int)$_GET['r'];
    if ($r != 0) $r = 1;
    $rels = array('<', '>');
    $rel = $rels[$r];
    $db->sql = "SELECT id,`order` FROM lejarat WHERE id='$o'";
    $db->query();
    $c = mysql_fetch_row($db->rs);
    $db->sql = "SELECT id,`order` FROM lejarat
                WHERE `order`$rel'" . $c[1] . "'
                ORDER BY `order` " . ($rel == '<' ? 'DESC' : 'ASC') . "
                LIMIT 1";
    $db->query();
    if (mysql_num_rows($db->rs) == 1) {
        $n = mysql_fetch_row($db->rs);
        $db->sql = "UPDATE lejarat SET `order`='" . $c[1] . "' WHERE id='" . $n[0] . "'";
        $db->query();
        $db->sql = "UPDATE lejarat SET `order`='" . $n[1] . "' WHERE id='" . $c[0] . "'";
        $db->query();
    }
}
#/sortable#
$rpp = 15; //row per page
//total count
$db->sql = "SELECT COUNT(id) FROM lejarat";
$db->query();
$tct = mysql_fetch_row($db->rs);
$tct = $tct[0];
$pager_options = array('mode' => 'Sliding', 'perPage' => $rpp, 'delta' => 2, 'totalItems' => $tct,);
$pager = @Pager::factory($pager_options);
list($from, $to) = $pager->getOffsetByPageId();
$db->sql = "SELECT id,lejarat_neve,lejarat_hossza FROM lejarat ORDER BY `order` LIMIT " . ($from - 1) . ", $rpp";
$db->query();
?>

<?php include ("header.php"); ?>

<p><ul id='breadcrumb'><li><a href='index.php' title='Home'><img src='images/home.png' alt='Home' class='home' /></a></li><li><a href='lejarat_list.php' title='lejarat'>Lejárat</a></li><li><a href='lejarat_list.php' title='lejarat-List'>List</a></li></ul></p>

<br />

<div id="wrapper">
	
<div id='menu'><ul class='first-level'><li><a href='rovat_list.php' title='Rovat'>Rovat</a></li><ul class='second-level'><li><a href='rovat_create.php' title='Rovat-Create'>Create</a></li><li><a href='rovat_list.php' title='Rovat-List'>List</a></li></ul></ul><ul class='first-level'><li><a href='regio_list.php' title='Régió'>Régió</a></li><ul class='second-level'><li><a href='regio_create.php' title='Régió-Create'>Create</a></li><li><a href='regio_list.php' title='Régió-List'>List</a></li></ul></ul><ul class='first-level'><li><a href='lejarat_list.php' title='Lejárat'>Lejárat</a></li><ul class='second-level'><li><a href='lejarat_create.php' title='Lejárat-Create'>Create</a></li><li><a href='lejarat_list.php' title='Lejárat-List'>List</a></li></ul></ul><ul class='first-level'><li><a href='hirdetes_list.php' title='Hirdetés'>Hirdetés</a></li><ul class='second-level'><li><a href='hirdetes_create.php' title='Hirdetés-Create'>Create</a></li><li><a href='hirdetes_list.php' title='Hirdetés-List'>List</a></li></ul></ul><ul class='first-level'><li><a href='kiemeles_list.php' title='Kiemelés'>Kiemelés</a></li><ul class='second-level'><li><a href='kiemeles_create.php' title='Kiemelés-Create'>Create</a></li><li><a href='kiemeles_list.php' title='Kiemelés-List'>List</a></li></ul></ul></div>

<div id="content">

<a name="table"></a>

<table class="table">
	<thead>
		<tr>
			<th>Id</th>
			<th>Lejarat neve</th><th>Lejárat hossza</th>
			<th>Operations</th>
		</tr>
	</thead>
	<tbody>	
<?php
if (mysql_num_rows($db->rs) < 1) print "<tr><td colspan='4'>No records.</td></tr>";
while ($row = mysql_fetch_array($db->rs)) {
?>
		<tr>
<?php
    print "<td>" . $row['id'] . "</td>";
    print "<td>" . $row['lejarat_neve'] . "</td>";
    print "<td>" . $row['lejarat_hossza'] . "</td>";
?>	
			<td>
				Edit
				<a href=<?php print "'" . $_SERVER['SCRIPT_NAME'] . "?d=" . $row[0] . "&t=" . time() . "#table'"; ?> onclick="return confirm ('Are you sure to delete?')">Delete</a>		
				<?php #sortable#
     ?>
				<a href=<?php print "'" . $_SERVER['SCRIPT_NAME'] . "?o=" . $row[0] . "&r=0&t=" . time() . "#table'"; ?>>Up</a>
				<a href=<?php print "'" . $_SERVER['SCRIPT_NAME'] . "?o=" . $row[0] . "&r=1&t=" . time() . "#table'"; ?>>Down</a>
				<?php #/sortable#
     ?>
			</td>	
		</tr>
<?php
}
?>
	</tbody>
</table>

</div>

</div>

<br class='clear:both' />

<?php echo $pager->links; ?>

<?php include ("footer.php"); ?>
